package neuralmusic.brain.module;

import java.util.List;
import java.util.Random;

public class Noise extends  BasicDelayed {

	

	private double noise;
	private double dt;
	private double fireFact;
	private List<Neuron> neurons;
	private Random rand;


	Noise(Scheduler queue,List<Neuron> neurons,
			double dt,double fireFact,double noise,Random rand){
		super(queue);
		assert(queue != null);
		
		this.noise=noise;
		this.dt=dt;
		this.fireFact=fireFact;
		this.neurons=neurons;
		this.rand=rand;
	}
	

	@Override
	public void fireImpl(Scheduler sched) throws BrainException {
		
		int nn=neurons.size();
		int n=(int) (nn*fireFact);
		
		for (int i=0;i<n;i++) {
			Neuron neuron=neurons.get(rand.nextInt(nn));
			if (neuron.isFiring()) continue;
			neuron.excite((float) noise);			
		}
		
		fireAtDelta(dt);
	}

}
